
export function prefix(prefix : string,data,tail:string ='.') {
    type ArrType = Parameters<typeof data>
    return data.map(o=>prefix?prefix + tail + o:o) as any
}

export function hump2UnderLine(s)
{
    let comps = s.match(/([A-Z][a-z]+)+?/g)
    if(!comps) return s
    let keys : [] = comps.map(o=>o.toLowerCase()) 
    let strArr : never = s.match(/[a-z]+/)[0] as never
    keys.unshift(strArr)
    
    s = keys.join('_')

    return s
}

export function hump2UnderLineForObject(obj)
{
    var temp = {}
    for (const key in obj) {
        temp[hump2UnderLine(key)] = obj[key]
    }
    return temp
}

export function hump2UnderLineForArray(arr)
{
    return arr.map(hump2UnderLineForObject)
}

export function knexPrefix(strArr,prefix ?: string,tail:string ='.') {
    type ArrType = Parameters<typeof strArr>

    return strArr.map(s=>{ 
        let comps = s.match(/([A-Z][a-z]+)+?/g)
        if(!comps) return s
        let keys : [] = comps.map(o=>o.toLowerCase()) 
        let strArr : never = s.match(/[a-z]+/)[0] as never
        keys.unshift(strArr)
        
        s = keys.join('_')

        return prefix?(prefix + tail + s) : s
    }) as any
}

